/**
 * Created by LeonTao on 17/3/26.
 */

$(document).ready(function () {
    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = decodeURIComponent(window.location.search.substring(1)),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : sParameterName[1];
            }
        }
    };

    //获取用户id
    var search = getUrlParameter('search');
    $('#search-input').val(search);

    $('tbody img').on('click', function (e) {

        console.log('--- click ---', this);

        window.location.href = '/image-detail';

    });

    //点击搜索按钮
    $('.user-search-btn').on('click', function (e) {

        var searchInput = $('#search-input').val();
        console.log('--- search : ---', searchInput);

        if(searchInput.trim() === ''){
            return;
        }
        // window.location.href = '/image-retrieval-list?search=' + searchInput;
        var from = 0;
        var size = 10;

        if(searchInput.trim() != '')
            $(location).attr('href', '/image-retrieval-list?search=' + searchInput + "&from=" + from + "&size=" + size);

    });

    $('.user-search-btn').on('keydown', function (event) {
        console.log(" --- keydown --- " + event.which);
        if ((event.which === 13)) {
            //与服务器进行交互
            var searchInput = $('#search-input').val();
            var from = 0;
            var size = 10;

            if(searchInput.trim() != '')
                $(location).attr('href', '/image-retrieval-list?search=' + searchInput + "&from=" + from + "&size=" + size);
        }

    });


});